﻿#region Opis pliku
//-----------------------------------------------------------------------------
// Factory.cs
// Autor: Jan Fraś
// 30.10.2012
//-----------------------------------------------------------------------------
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace pogra
{
    /// <summary>
    /// fabryka, produkuje się tu czołgi i inne żelastwo. 
    /// </summary>
    class Factory:Buildings
    {
        List<Unit> teamlist;
        Texture2D tanktexA;
        private int counter = 0;
        public static int kosztBudowy = 3000;

        public Factory(Vector2 pos, float rotation, int team, List<Unit> teamlist, List<Unit> enemyteam, Texture2D tanktexA, Texture2D factorytex, Texture2D particletexture) :
            base (pos, rotation, team, enemyteam, factorytex)
        {
            kosztProdukcji = 700;
            hp = 100;
            amountToBulid = 00;
            spawninterval = 4000;
            timeOfConstruction = 10000;
            this.teamlist = teamlist;
            this.tanktexA = tanktexA;
            this.particletexture = particletexture;
        }


        protected override void WorkingState(TimeSpan time)
        {

            if (amountToBulid > 0 && this.time > spawninterval)
            {
                amountToBulid--;
                Random random = new Random();
                Tank temp = new Tank(position, rotation/*(float)(new Random().NextDouble() * Math.PI * 2)*/, team, tanktexA, particletexture, enemyteam, 0.1f);
                temp.setGoalPosition(new Point((int)(position.X + random.Next(0, 100) + Math.Cos(rotation) * 200), (int)(position.Y +random.Next(0,100)+ Math.Sin(rotation) * 200)));
                teamlist.Add(temp);
                
                counter++;
                this.time = 0;
            }
            
            if(particleSystem.Count<50)
                particleSystem.AddEmitter(new SmokeEmitter(position+new Vector2(-(float)Math.Cos(rotation+1.6)*30,-(float)Math.Sin(rotation+1.6)*30),0,(float)Rand.next(0,10)));

            base.WorkingState(time);
        }
    }
}
